// pages/ruzhu/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    images: [],
    upload: 0,
    photos: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  chooseImg() {
    let that = this;
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        that.data.photos = res.tempFilePaths
        that.setData({
          imgUrls: [...(res.tempFilePaths || [])]
        });
      }
    });
  },

  formSubmit: function (e) {
    var that = this;
    var form = e.detail.value;
    wx.uploadFile({
      url: app.globalData.headurl + '/goods/upload', //仅为示例，非真实的接口地址
      filePath: that.data.photos[0],
      name: 'file',
      formData: {},
      success: function (res) {
        var filename = res.data;
        filename = filename.replace("\"", "").replace("\"", "");
        wx.request({
          url: app.globalData.headurl + '/Lfdshop/sign',
          data: {
            openid: app.globalData.openid,
            address: app.globalData.address,
            brief: form.brief,
            dname: form.dname,
            name: form.name,
            price: form.price,
            // phone:form.phone,
            pwd: form.pwd,
            img: filename
          },
          method: "POST",
          header: {
            "content-type": "application/x-www-form-urlencoded;charset=utf-8",
          },
          success: function (re) {
            wx.showToast({
              title: '提交成功',
            })
            wx.navigateBack({})

          }
        })
      }
    })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },


  getwz: function () {
    wx.navigateTo({
      url: '../shopmap/index',
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      address: app.globalData.address
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})